package com.cnblogs.leizia.crm.settings.service.impl;

import com.cnblogs.leizia.crm.settings.dao.SysInitDicTypeDao;
import com.cnblogs.leizia.crm.settings.dao.SysInitDicValueDao;
import com.cnblogs.leizia.crm.settings.domain.DicType;
import com.cnblogs.leizia.crm.settings.domain.DicValue;
import com.cnblogs.leizia.crm.settings.service.SysInitDicService;
import com.cnblogs.leizia.crm.utils.SqlSessionUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author leizi
 * @create 2021-03-01 22:38
 */
public class SysInitDicServiceImpl implements SysInitDicService {
    /**
     * 获取数据字典
     *
     * @return
     */
    @Override
    public Map<String, List<DicValue>> getDicValues() {
        SysInitDicTypeDao dicTypeDao = SqlSessionUtil.getSqlSession().getMapper(SysInitDicTypeDao.class);
        SysInitDicValueDao dicValueDao = SqlSessionUtil.getSqlSession().getMapper(SysInitDicValueDao.class);

       Map<String, List<DicValue>> dicValueMap = new HashMap<>();

        // 获取数据字典类型type
        List<DicType> dicTypes = dicTypeDao.getDicTypes();

        for (DicType dicType : dicTypes) {
            String code = dicType.getCode();
            // 根据数据字典typeCode获取对应Value
            List<DicValue> dicValues = dicValueDao.getDicValues(code);
            dicValueMap.put(code, dicValues);
        }

        return dicValueMap;
    }
}
